package com.dobby.logger.system.aop;

import com.dobby.logger.system.service.SystemLogService;
import com.dobby.logger.system.vo.SystemLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by liguoqing on 2016/3/8.
 */
@Component
public class AsynAddLogHandler {

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private SystemLogService systemLogService;

    private static final Logger logger = LoggerFactory.getLogger(AsynAddLogHandler.class);

    /**
     * 添加系统日志
     */
    public void addSysLog(SystemLog systemLog) {
        logger.info("开始记录日志...." + new Date());
        AddSystemLog addSystemLog = new AddSystemLog(systemLog);
        taskExecutor.execute(addSystemLog);
        logger.info("结束记录日志...." + new Date());
    }

    private class AddSystemLog implements Runnable {

        private SystemLog systemLog;

        public AddSystemLog(SystemLog systemLog) {
            this.systemLog = systemLog;
        }

        @Override
        public void run() {
            logger.info("我是日志..." + new Date());
        }
    }
}
